#include<stdio.h>
#include<stdlib.h>

typedef struct TreeNode
{
    struct TreeNode* left;
    struct TreeNode* right;
}TreeNode;

int maxDepth(struct TreeNode* root) {
    if (root == NULL)
    {
        return 0;
    }

    int maxleft = maxDepth(root->left);
    int maxright = maxDepth(root->right);
    return maxleft > maxright ? maxleft + 1 : maxright + 1;
}

int main()
{
    TreeNode* n1 = (TreeNode*)malloc(sizeof(TreeNode));
    TreeNode* n2 = (TreeNode*)malloc(sizeof(TreeNode));
    TreeNode* n3 = (TreeNode*)malloc(sizeof(TreeNode));
    TreeNode* n4 = (TreeNode*)malloc(sizeof(TreeNode));
    TreeNode* n5 = (TreeNode*)malloc(sizeof(TreeNode));
    if (n1 == NULL || n2 == NULL || n3 == NULL || n4 == NULL || n5 == NULL)
    {
        perror("malloc failure");
        return 1;
    }
    n2->left = NULL;
    n2->right = NULL;
    n4->left = NULL;
    n4->right = NULL;
    n5->left = NULL;
    n5->right = NULL;

    n1->left = n2;
    n1->right = n3;
    n3->left = n4;
    n3->right = n5;

    printf("%d\n", maxDepth(n1));
    return 0;
}